﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Infinity.Models;
using PagedList;
using PagedList.Mvc;

namespace Infinity.Areas.Managerial.Controllers
{
    public class PaymetMethodController : Controller
    {
        private InfinityEntities db = new InfinityEntities();

        //
        // GET: /PaymetMethod/

        public ActionResult Index(string searchBy, string search, int? page)
        {

            if (searchBy == "SalaryType")
            {
                return View(db.Instructor_Salary.Where(x => x.SalaryType.Contains(search) || search == null).ToList().ToPagedList(page ?? 1, 4));
            }

            else
            {
                return View(db.Instructor_Salary.Where(x => x.SalaryType.Contains(search) || search == null).ToList().ToPagedList(page ?? 1, 4));
            }
            
        }

       



        //
        // GET: /PaymetMethod/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /PaymetMethod/Create

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(Instructor_Salary instructor_salary)
        {
            if (ModelState.IsValid)
            {
                db.Instructor_Salary.Add(instructor_salary);
                db.SaveChanges();
                //return RedirectToAction("Index");
            }

            return View(instructor_salary);
        }

        //
        // GET: /PaymetMethod/Edit/5

        public ActionResult Edit(int id = 0)
        {
            Instructor_Salary instructor_salary = db.Instructor_Salary.Find(id);
            if (instructor_salary == null)
            {
                return HttpNotFound();
            }
            return View(instructor_salary);
        }

        //
        // POST: /PaymetMethod/Edit/5

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(Instructor_Salary instructor_salary)
        {
            if (ModelState.IsValid)
            {
                db.Entry(instructor_salary).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(instructor_salary);
        }

        //
        // GET: /PaymetMethod/Delete/5

        public ActionResult Delete(int id = 0)
        {
            Instructor_Salary instructor_salary = db.Instructor_Salary.Find(id);
            if (instructor_salary == null)
            {
                return HttpNotFound();
            }
            return View(instructor_salary);
        }

        //
        // POST: /PaymetMethod/Delete/5

        [HttpPost, ActionName("Delete")]
        //[ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            Instructor_Salary instructor_salary = db.Instructor_Salary.Find(id);
            db.Instructor_Salary.Remove(instructor_salary);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}